// run: $exec < input
// opt: 0
// flag: -g
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>

struct data
{
	int x, y, z;
};

struct pair
{
	int x, v;
};

bool cmp1(pair const& a, pair const& b)
{
	return a.x < b.x || (a.x == b.x && a.v > b.v);
}

bool cmp2(pair const& a, pair const& b)
{
	return a.x > b.x || (a.x == b.x && a.v > b.v);
}

int const maxn = 10007;
data left[maxn], right[maxn];
std::set<int> dis;
int left_sum[2 * maxn];
int right_sum[2 * maxn];
int tl, tr;
int n;
int size;
int adis[2 * maxn];

bool too_long(data const& a)
{
	return a.y - a.x > 2 * a.z;
}

pair v[2 * maxn];
int len = 0;

int main()
{
	int T;
	scanf("%d", &T);
	for (int ti = 1; ti <= T; ti++) {
		tl = tr = 0;
		dis.clear();
		printf("Case #%d:\n", ti);
		scanf("%d", &n);
		data tmp;
		for (int i = 0, d; i < n; i++) {
			scanf("%d%d%d%d", &tmp.x, &tmp.y, &tmp.z, &d);
			if (too_long(tmp)) continue;
			if (d == -1) left[tl++] = tmp;
			else right[tr++] = tmp;
			dis.insert(tmp.y - tmp.z);
			dis.insert(tmp.x + tmp.z);
		}
		len = 0;
		size = 0;
		for (std::set<int>::iterator it = dis.begin(); it != dis.end(); ++it)
			adis[size++] = *it;
		for (int i = 0; i < tl; i++) {
			pair tmp;
			tmp.x = left[i].y - left[i].z;
			tmp.v = 1;
			v[len++] = tmp;
			tmp.x = left[i].x + left[i].z;
			tmp.v = -1;
			v[len++] = tmp;
		}
		std::sort(v, v + len, cmp1);
		int sum = 0, t = 0;
		int tot = 0;
		for (int it = 0; it < size; it++) {
			while (t < len && v[t].x <= adis[it] && v[t].v > 0)
				sum += v[t++].v;
			left_sum[tot++] = sum;
			while (t < len && v[t].x <= adis[it])
				sum += v[t++].v;
		}

		len = 0;
		for (int i = 0; i < tr; i++) {
			pair tmp;
			tmp.x = right[i].y - right[i].z;
			tmp.v = -1;
			v[len++] = tmp;
			tmp.x = right[i].x + right[i].z;
			tmp.v = +1;
			v[len++] = tmp;
		}
		std::sort(v, v + len, cmp2);
		sum = t = tot = 0;
		for (int it = size - 1; it >= 0; it--) {
			while (t < len && v[t].x >= adis[it] && v[t].v > 0)
				sum += v[t++].v;
			right_sum[size - (++tot)] = sum;
			while (t < len && v[t].x >= adis[it])
				sum += v[t++].v;
		}
		int max = 0, ans = 0;
		tot = 0;
		for (std::set<int>::iterator it = dis.begin(); it != dis.end(); ++it) {
			max = std::max(max, right_sum[tot]);
			ans = std::max(ans, left_sum[tot++] + max);
		}
		printf("%d\n", ans);
	}
}

